package org.nstack.header.cluster;

import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.springframework.http.HttpMethod;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;


@RestRequest(
        path = "/clusters/{uuid}/actions",
        method = HttpMethod.PUT,
        isAction = true,
        responseClass = APIChangeClusterStateEvent.class
)
public class APIChangeClusterStateMsg extends APIMessage implements ClusterMessage {

    @APIParam(resourceType = ClusterVO.class)
    private String uuid;

    @APIParam(validValues = {"enable", "disable"})
    private String stateEvent;

    public APIChangeClusterStateMsg() {
    }

    public APIChangeClusterStateMsg(String uuid, String stateEvent) {
        this.uuid = uuid;
        this.stateEvent = stateEvent;
    }

    public void setUuid(String clusterUuid) {
        this.uuid = clusterUuid;
    }

    public String getStateEvent() {
        return stateEvent;
    }

    public void setStateEvent(String stateEvent) {
        this.stateEvent = stateEvent;
    }

    public String getUuid() {
        return uuid;
    }

    @Override
    public String getClusterUuid() {
        return getUuid();
    }
 
    public static APIChangeClusterStateMsg __example__() {
        APIChangeClusterStateMsg msg = new APIChangeClusterStateMsg();
        msg.setUuid(uuid());
        msg.setStateEvent("disable");
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                ntfy("Changed the state to %s", ((APIChangeClusterStateEvent)evt).getInventory().getState())
                        .resource(uuid, ClusterVO.class.getSimpleName())
                        .messageAndEvent(that, evt).done();
            }
        };
    }

}
